<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>好友列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <style>
        .childrenBody{
            padding: 30px;
        }
    </style>
</head>
<body class="childrenBody">

<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <!--<input type="checkbox" name="status" lay-skin="switch" checked lay-filter="status" lay-text="开启|冻结">-->
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="name" placeholder="用户昵称" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="mobile" placeholder="手机号" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="ucode" placeholder="应用ID" class="layui-input height33">
        </div>
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'menu.id', title: '好友ID', width: '15%', align: 'center', templet: function (d) {
                    return d.userId;
                }

                }
                , {
                    field: 'menu.name', title: '头像', align: 'center', width: '15%', templet: function (d) {
                        return d.avatar == null ? "" : ("<img width='30' height='30' src='" + d.avatar + "'/>");
                    }
                }
                , {
                    field: 'pName', title: '昵称', width: '15%', align: 'center', templet: function (d) {
                        return d.nick;
                    }
                }

                , {
                    field: 'pName', title: '手机号', width: '15%', align: 'center', templet: function (d) {
                        return d.mobile;
                    }
                }

                , {
                    field: 'pName', title: '好友备注', width: '15%', align: 'center', templet: function (d) {
                        return d.remark == null ? '' : d.remark;
                    }
                }
                , {
                    field: 'appId', title: '应用ID', width: '10%', align: 'center'
                }
                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    width: "15%",
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }


            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/member/friend/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , limit: 10 //默认采用0
            , loading: true
            , where:  {
                id:[[${id}]]
            }
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '添加用户',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/member/save/index'
                    });
                    break;
                case 'groupAuthAll':
                    layer.confirm("确定所有用户拥有建群权限?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/group/auth/all",
                            data: {},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("操作完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });

                    });
                break;
                case 'groupAuthNone':
                    layer.confirm("确定所有用户没有建群权限?", {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/group/auth/none",
                            data: {},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("操作完成", {icon: 1}, 500);

                                    layer.close(index);

                                    tableIns.reload();
                                }
                            }
                        });

                    });
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                layer.open({
                    type: 2,
                    title: '用户详情',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/member/detail?id=' + data.id
                });

            }

            //清除登录token
            if (obj.event === 'delete') {

                layer.confirm("确定删除该用户？", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/clean/login/status",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("清除完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                });

            }

            if (obj.event === 'groupAuth') {

                var te = (data.createGroupAuth==null||data.createGroupAuth == 0) ? ("确定给该用户拥有建群权限吗？") : ("确定取消用户拥有建群权限吗？");

                layer.confirm(te, {
                    icon: 3,
                    title: '提示'
                }, function (index) {


                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/group/auth",
                        data: {userId: data.id, status: data.createGroupAuth == 0 ? 1 : 0},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("权限修改成功！", {icon: 1}, 2000);

                                layer.close(index);

                                setTimeout(function () {
                                    tableIns.reload();
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });


                }, function (index) {


                });
            }

            if (obj.event === 'changePassword') {

                layer.confirm("确定修改该用户密码?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    layer.prompt({
                        formType: 0,
                        value: '111111',
                        title: '请输入密码',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem){


                        if(value==null||value==''){
                            layer.msg("密码不能为空",{icon:6,time:1500});
                            return;
                        }

                        $.ajax({
                            type: "post",
                            url: [[${basePath}]] + "/member/password/change",
                            data: {userId: data.id,password:value},
                            success: function (res) {
                                if (res.success) {
                                    layer.msg("密码修改成功！", {icon: 1}, 2000);

                                    layer.close(index);

                                    setTimeout(function () {
                                        tableIns.reload();
                                    },2000);
                                }else{
                                    layer.msg(res.msg, {icon: 2}, 2000);
                                }
                            }
                        });

                        layer.close(index);
                    });


                }, function (index) {


                });
            }



        });


        var status = 0;
        form.on('switch(status)', function (data) {
            if (!data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }

            $("#search").click();

        });


        var groupAuth=null;
        form.on('select(groupAuth)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            groupAuth=(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
        });

        function getJson() {
            return {
                where: {
                    id:[[${id}]]
                }
            };
        }

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    id:[[${id}]]
                },
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <!--<i class="layui-icon layui-icon-file" style="cursor: pointer" lay-event="edit"></i>-->
    <i class="layui-icon layui-icon-engine" title="删除用户" style="cursor: pointer" lay-event="delete"></i>
    <i class="layui-icon layui-icon-edit" title="修改密码" style="cursor: pointer" lay-event="changePassword"></i>
    <i class="layui-icon layui-icon-password" title="建群权限" style="cursor: pointer" lay-event="groupAuth"></i>
</script>
</body>
</html>